/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package servlet;

import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.*;
import java.sql.*;
import javax.servlet.http.*;
import business.ShowMember;

/**
 *
 * @author User
 */
public class DeleteMemberServlet extends HttpServlet {

    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        try {
        } finally {
            out.close();
        }
    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {

        String message = "";
        Statement stmt = null;
        ResultSet rs = null;
        String idEdit = request.getParameter("ed_id");
//        System.out.println(idEdit);
       
// res.setContentType("text/html");
        PrintWriter out = response.getWriter();
        Connection conn = null;
//using movie_resolved view
        String connectionURL = "jdbc:mysql://localhost:3306/cemilansehat";
        Connection connection = null;

        response.setContentType("text/html");
        try {
            Class.forName("com.mysql.jdbc.Driver");
            // Get a Connection to the database
            connection = DriverManager.getConnection(connectionURL, "root", "");
            //Select the data from the database
            String sql = "delete from member where id_member='" + idEdit + "'";
            System.out.println(idEdit);
            Statement s = connection.createStatement();
            s.executeUpdate(sql);
            int editTabel = s.executeUpdate(sql);
            
            if (editTabel == 1) {
                message = "failed to delete";
            } else {
                message = "data have been deleted";
            }
            request.setAttribute("message", message);
            RequestDispatcher view = request.getRequestDispatcher("ShowMemberServlet");
            view.forward(request, response);

        } catch (ClassNotFoundException e) {
            out.println("Couldn't load database driver: " + e.getMessage());
        } catch (SQLException e) {
            out.println("SQLException caught: " + e.getMessage());
        } finally {
// Always close the database connection.
            try {
                if (conn != null) {
                    conn.close();
                }
            } catch (SQLException ignored) {
            }
        }

    }

//    @Override
//    protected void doPost(HttpServletRequest request, HttpServletResponse response)
//            throws ServletException, IOException {
//        processRequest(request, response);
//    }

    /** 
     * Returns a short description of the servlet.
     * @return a String containing servlet description
     */
    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>
}
